import requests
import json
requests.packages.urllib3.disable_warnings()




# url = 'http://shop-xo.hctestedu.com'

# 案列一：无可选参数
# 方法一

# res_one = requests.request("GET",url = url)
#
# print(res_one)
# print(type(res_one))
# print(res_one.url)
# print(res_one.text)

#方法二
# res_two = requests.get(url= url)
# print(res_two)
# print(type(res_two))
# print(res_two.url)
# print(res_two.text)


# 案列二：公共参数
# 方法一 (公共参数,直接拼接在url后面)
# url = 'http://shop-xo.hctestedu.com?application=app&application_client_type=pc'
# res_one = requests.request("GET",url = url)
#
# print(res_one)
# print(type(res_one))
# print(res_one.url)
# print(res_one.text)
# 加上这行代码即可，关闭安全请求警告

# host = "https://test.inis.cn"
# path = "/api/users/all"
# url = host + path
# pub_params = {
#     "page": 1,
#     "limit": 5,
#     "order": "create_time asc",
#     "cache": "true"
# }
# print(url)
# re = requests.request("GET",url=url,params=pub_params,verify= False)
# print(re)
# print(re.url)
# res = re.text
# print(res)
# a = json.loads(res )
# print(a)
# b = json.dumps(a, sort_keys=True, indent=4, separators=(',', ':'),ensure_ascii=False)
# print(b)





# 方法二(公共参数，添加到params中)
# url = "http://shop-xo.hctestedu.com"
# pub_params = {
#     "application": "app",
#     "application_client_type": "pc"
# }
# res_two = requests.get(url= url,params=pub_params)
# print(res_two)
# print(type(res_two))
# print(res_two.url)
# print(res_two.text)



host = 'https://echo.apifox.com'
path = '/anything'

pub_params = {
    "type": "app",
    "client": "pc"
}

data_body = {
    "name": "felix",
    "age": 18
}

header = {
    "Content-Type": "application/json"
}

url = host + path
re = requests.get(url= url,params=pub_params,data=json.dumps(data_body),headers=header)

# 打印请求数据
# print(响应对象.request.方法/属性)
print(re.request.url)
print(re.request.headers)
print(re.request.method)
print(re.request.body)

# 打印响应数据
# print(响应对象.方法/属性)
print(re.url)
print(re.text)
print(re.json())

